﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Webcar.BLL;
using System.Data;
using ToolsLayer;

namespace Webcar.UI
{
    public partial class RecentSendCar : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (this.IsPostBack) return;
                string sql = @"select top 14 a.*,b.dept_name from v_bs_car_send a ,dept b where a.dept_code=b.dept_code and a.dept_delflag='F'  and a.dept_code in 
            (select dept_code from bs_man_dept where man_code='{0}') 
            and (a.child_dept in (select child_dept from bs_man_childdept where userid='{0}') or a.child_dept is null  or a.child_dept='') order by a.start_date desc";
                sql = string.Format(sql, CurrentUser.LoginUserID);
                if (CurrentUser.IsSuperUser())
                {
                    sql = @"select top 14 a.*,b.dept_name from v_bs_car_send a ,dept b where a.dept_code=b.dept_code and a.dept_delflag='F' order by a.start_date desc";
                }
                
                this.Repeater1.DataSource = DB.ExecuteDataset(sql);
                this.Repeater1.DataBind();
            }
            catch (Exception ex)
            {
                new CurrentUser().LogError(ex);
            }
        }
        protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            HyperLink link = (HyperLink)e.Item.FindControl("hyperlink1");
            DataRowView row = e.Item.DataItem as DataRowView;
            string xh = row["xh"].ToString();
            Label newlabel = (Label)e.Item.FindControl("newlabel");

            InfoChecker ic = new InfoChecker();
            newlabel.Visible = !ic.InfoIsRead(xh, InfoCheckType.CarSend);

            string url = "car/SendCarPopView.aspx?xh=" + xh;
            link.NavigateUrl = "javascript:openDialog('" + url + "',710,480);";
        }
    }
}